package com.wsq.global;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Vibrator;
import android.preference.PreferenceManager;

public class Configuration {

	public static Configuration configuration;

	public SharedPreferences mDefaultPreferences;

	public static Configuration instance() {
		if (configuration == null) {
			configuration = new Configuration();
		}
		return configuration;
	}

	public static Vibrator sVibrator;

	public void playVibrate(Activity context) {
		if (sVibrator == null) {
			sVibrator = (Vibrator) context
					.getSystemService(Context.VIBRATOR_SERVICE);
		}
		if (mDefaultPreferences == null) {
			mDefaultPreferences = PreferenceManager
					.getDefaultSharedPreferences(context);
		}
		int vibrateTime = mDefaultPreferences.getInt("feedback_time", 45);
		sVibrator.vibrate(vibrateTime);
	}

	public void vibrate(Context context, int vibrateTime) {
		if (sVibrator == null) {
			sVibrator = (Vibrator) context
					.getSystemService(Context.VIBRATOR_SERVICE);
		}
		sVibrator.vibrate(vibrateTime);
	}
}
